package algorithm.view.prepare;

import java.awt.*;
import java.awt.event.*;


/**
 * @author bingo
 * @Description 移动鼠标更改背景
 * @Date 2018/7/20
 */
public class Demo4 {
    public static void main(String[] args) {
        Frame f = new Frame();
        f.setSize(400,400);
        f.setVisible(true);
        f.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        f.setLayout(new FlowLayout());
        Button button1 = new Button("青色");
        TextField t = new TextField(20);
        t.addKeyListener(new KeyAdapter() {
          @Override
            public void keyPressed(KeyEvent e) {
                char ch = e.getKeyChar();
              System.out.println(ch);
                if(!(ch>='0'&&ch<='9')){
                    e.consume();
                }
            }
        });


        f.add(button1);
        f.add(t);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
                f.setBackground(Color.cyan);
            }
        });


    }
}
